%
% This calculates the area of a normal fuzzy number in the two-column interval format.
% It assumes intrinsic alphas evenly spaced from [0,1], and performs linear interpolation
% to produce it's calculation of the area. 
% No sanity checking is performed, so if your intervals are bad, your result is junk 
%
function A = fuzzy_area(x)

N = length(x);

% delta alpha 
da = 1/(N-1);

% delta left 
dl = x(2:end,1) - x(1:end-1,1);

% delta right
dr = x(1:end-1,2) - x(2:end,2);

% sum of both differences
ds = dl + dr;

% indices
index = [1:N-1];

%modified indices
m_index = 2 .* index - 1;

%scaled sum
ss = m_index * ds;

% area of the peak
ap = x(end,2) - x(end,1);

% Total area is the delta alpha times the sum divided by two, plus the peak length 
A = da .* ss ./ 2 + ap;
